package com.onemile.controls;

import java.util.ArrayList;

import com.onemile.app.R;
import com.onemile.entity.model.EAttribute;
import com.onemile.entity.model.EAttributeDetails;
import com.onemile.utils.UtiDialogsFactory;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class AdpCstLV_Attribute extends BaseAdapter
{

   private ArrayList<EAttribute> mList;
   private Context mContext;
   private LayoutInflater mInflater;
   
   private ArrayList<EAttributeDetails> attriList;
   
   public AdpCstLV_Attribute(ArrayList<EAttribute> list, Context context)
   {
	  mList = list;
	  mContext = context;
	  mInflater = LayoutInflater.from(mContext);
	  attriList=new ArrayList<EAttributeDetails>();
   }

   @Override
   public int getCount()
   {
	  int size=mList.size();
	  return size;
   }

   @Override
   public Object getItem(int position)
   {
	  return mList.get(position);
   }

   @Override
   public long getItemId(int position)
   {
	  return 0;
   }

   public ArrayList<EAttributeDetails> getSelectAttributeDetails()
   {
	  return attriList;
   }
   
   @Override
   public View getView(final int position, View convertView, ViewGroup parent)
   {
	  convertView = mInflater.inflate(R.layout.commoditylist_item_select_item, null);
	  TextView txtAttr = (TextView) convertView.findViewById(R.id.txtAttribute_commodity_item_select);
	  final TextView txtAttrDetail = (TextView) convertView.findViewById(R.id.txtAttributeDetails_commodity_item_select);
	  txtAttr.setText(mList.get(position).getAttributeName());
	  // txtAttr.setTag(mList.get(position).getAttributeId());

	  txtAttrDetail.setText(mContext.getString(R.string.all_plase_select));
//	  txtAttrDetail.setTag(position);
	  txtAttrDetail.setOnClickListener(new View.OnClickListener()
	  {
		 @Override
		 public void onClick(View v)
		 {
			UtiDialogsFactory.getInstance().ShowSingleSelectItemDialog(mContext, mList.get(position).getAttributeDetailsList(), null,
				  new UtiDialogsFactory.DialogCallBack()
				  {
					 @Override
					 public void SingleSelectDialogItemClick(ListView listView, View currentView, int index)
					 {
					   txtAttrDetail.setText(mList.get(position).getAttributeDetailsList().get(index).getAttributeDetailsName());
					   attriList.add(mList.get(position).getAttributeDetailsList().get(index));
					 }
					 @Override
					 public void MultiSelectDialogOKClick(ListView listView, ArrayList<Integer> selectList, int count)
					 {}
				  });
		 }
	  });
	  return convertView;
   }
}
